<template>
    <div>
        <Row class="margin-top-10">
            <Card>
                <p slot="title" class="card-title">
                    <Icon type="ios-pulse"></Icon>
                    {{this.$route.meta.title}}
                </p>
                <div class="line-chart-con">
                    <Table border stripe :columns="title" :data="data" ></Table>
                </div>
            </Card>
        </Row>
        <Modal
            title="修改预设"
            v-model="modal"
            @on-ok="bcModal"
            class-name="vertical-center-modal">
            <Form :model="formBatch" label-position="left" :label-width="100">
                <FormItem label="期号：">
                    <Input v-model="formBatch.issue"></Input>
                </FormItem>
                <FormItem label="开奖号：">
                    <Input v-model="formBatch.open_number" placeholder="请输入开奖号"></Input>
                </FormItem>
                <FormItem label="开奖日期：">
                    <DatePicker type="date" format="yyyy-MM-dd" v-model="formBatch.open_date"  placeholder="Select date" style="width: 200px"></DatePicker>
                </FormItem>
                <FormItem label="开奖时间：">
                    <TimePicker type="time" v-model="formBatch.open_time" placeholder="Select time" style="width: 200px"></TimePicker>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>


export default {
    components: {
        
    },
    data () {
        return {
            modal:false,
            formBatch:{
                index:0,
                gid:0,
                issue:'',
                lt_name:'',
                open_number:'',
                open_time: "06:30:00",
                open_date: "2018-05-30",
            },
            data:[],
            title:[
                {
                    title:'彩种',
                    key: 'lt_name',
                    align:'center',
                },
                {
                    title:'期数',
                    key: 'issue',
                    align:'center',
                },
                {
                    title:'开奖时间',
                    key: 'open_time',
                    align:'center',
                },
                {
                    title:'参与人数',
                    key: 'total_people',
                    align:'center',
                },
                {
                    title:'总投注额',
                    key: 'sum_order_money',
                    align:'center',
                },
                {
                    title:'操作',
                    key: '',
                    align:'center',
                    // width:'100'
                    render: (h, params) => {
                        let _this=this
                        return h('div',[
                            h('Button', {
                                props: {
                                    size: 'small',
                                    type:'primary',
                                },
                                style:{
                                    
                                },
                                on:{
                                    click(){
                                        _this.sdkj(params)
                                    }
                                }
                            },'手动开奖'),
                            // h('Button', {
                            //     props: {
                            //         size: 'small',
                            //         type:'primary',
                            //     },
                            //     style:{
                            //         marginLeft:'5px'
                            //     },
                            //     on:{
                            //         click(){
                            //             _this.hulue(params)
                            //         }
                            //     }
                            // },'忽略')
                        ])
                    }
                }
            ]
                
            
        }
    },
    computed: {
        
    },
    methods: {
        getOpenDetection(){
            this.$api.repeater(this,'getOpenDetection').then(res=>{
                if(res.success==true){
                    this.data=res.data
                }else{

                }
            })
            
            // this.$api.getOpenDetection().then(response=>{
            //     response.json().then(responseJson=> {
            //         if(responseJson.success==true){
            //             this.data=responseJson.data
            //         }else{

            //         }
                    
                    
            //     })
            // })
        },
        sdkj(p){
            this.modal=true
            let d=p.row.open_time.split(" ")
            this.formBatch={
                index:p.index,
                gid: p.row.gid,
                issue: p.row.issue,
                open_number: p.row.open_number,
                open_time: d[1],
                open_date: d[0],
                lt_name:p.row.lt_name,
            }

        },
        hulue(){

        },
        bcModal(){
            function gshdate(d){
                var date = new Date(d);  
                return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
            }
            let time = (data) =>{
                let date = new Date(data);
                let Y = date.getFullYear()
                let M = date.getMonth() + 1;
                let D = date.getDate();
                let h = date.getHours()
                let m = date.getMinutes()
                let s = date.getSeconds()
                if (M >= 1 && M <= 9) M = "0" + M;
                if (D >= 0 && D <= 9) D = "0" + D;
                if (h >= 0 && h <= 9) h = "0" + h;
                if (m >= 0 && m <= 9) m = "0" + m;
                if (s >= 0 && s <= 9) s = "0" + s;
                return `${Y}-${M}-${D}`
            }
            let data={
                gid:this.formBatch.gid,
                issue: this.formBatch.issue,
                open_number: this.formBatch.open_number,
                open_time: `${time(this.formBatch.open_date)} ${this.formBatch.open_time}`,
                lt_name: this.formBatch.lt_name
            }
            this.$api.repeater(this,'setOpenDetection',data).then(res=>{
                if(res.success==true){
                        this.$Notice.success({
                            title: '开奖成功'
                        });
                    }else{
                        this.$Notice.error({
                            title: '开奖失败'
                        });
                    }
            })
            // this.$api.setOpenDetection(data).then(response=>{
            //     response.json().then(responseJson=> {
            //         if(responseJson.success==true){
            //             this.$Notice.success({
            //                 title: '开奖成功'
            //             });
            //         }else{
            //             this.$Notice.error({
            //                 title: '开奖失败'
            //             });
            //         }
                    
                    
            //     })
            // })
        }
    },
    created(){
        this.getOpenDetection()
    }
};
</script>
